package com.woniu.liuzhougov.authorityControl.service.impl;

import com.woniu.liuzhougov.authorityControl.dao.RightsMapper;
import com.woniu.liuzhougov.authorityControl.pojo.Rights;
import com.woniu.liuzhougov.authorityControl.service.RightsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zhuxinpan
 * @version 1.0
 * @className RightsServiceImpl
 * @description
 * @date 2019/4/29 11:58
 */
@Service
public class RightsServiceImpl implements RightsService {
    @Resource
    private RightsMapper rightsMapper;

    /**
     * @param
     * @return java.util.List<com.woniu.liuzhougov.authorityControl.pojo.Rights>
     * @author zhuxinpan
     * @date 2019/4/29 12:00
     * @description 列出所有权限
     */
    @Override
    public List<Rights> listRights() {
        List<Rights> rightsList = rightsMapper.listRights();
        return rightsList;
    }

    /**
     * @param rights
     * @return int
     * @author zhuxinpan
     * @date 2019/4/29 19:30
     * @description 通过资源名查询数量
     */
    @Override
    public int countByRightsName(Rights rights) {
        return rightsMapper.countByRightsName(rights);
    }

    /**
     * @param rights
     * @return int
     * @author zhuxinpan
     * @date 2019/4/29 19:37
     * @description 添加资源
     */
    @Override
    public int insertRights(Rights rights) {
        return rightsMapper.insertSelective(rights);
    }

    /**
     * @param rightsId
     * @return com.woniu.liuzhougov.authorityControl.pojo.Rights
     * @author zhuxinpan
     * @date 2019/4/29 19:48
     * @description 通过主键查询
     */
    @Override
    public Rights getRightsByRightsId(Integer rightsId) {
        return rightsMapper.selectByPrimaryKey(rightsId);
    }

    /**
     * @param rights
     * @return int
     * @author zhuxinpan
     * @date 2019/4/29 19:48
     * @description 更新
     */
    @Override
    public int updateRightsByRightsId(Rights rights) {
        return rightsMapper.updateByPrimaryKey(rights);
    }

    /**
     * @param rightsId
     * @return int
     * @author zhuxinpan
     * @date 2019/4/29 20:18
     * @description 删除资源
     */
    @Override
    public int deleteRightsByRightsId(Integer rightsId) {
        return rightsMapper.deleteByPrimaryKey(rightsId);
    }

    /**
     * @param userId
     * @return java.util.List<java.lang.String>
     * @author zhuxinpan
     * @date 2019/4/30 11:56
     * @description 通过用户id列出他拥有的权限
     */
    @Override
    public List<String> listPermsByUserId(Integer userId) {
        return rightsMapper.listPermsByUserId(userId);
    }

    /**
     * @param rights
     * @return int
     * @author zhuxinpan
     * @date 2019/4/30 11:35
     * @description 判断权限标识的数量
     */
    @Override
    public int countNumberByPerms(Rights rights) {
        return rightsMapper.countNumberByPerms(rights);
    }

    /**
     * @param parentId
     * @return int
     * @author zhuxinpan
     * @date 2019/4/30 11:26
     * @description 查找rights表中父节点id为parentId的数量
     */
    @Override
    public int countNumberByParentId(Integer parentId) {
        return rightsMapper.countNumberByParentId(parentId);
    }
}
